package com.heima.schedule.client;

import com.heima.api.ScheduleFeignClient;
import com.heima.model.schedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import javafx.concurrent.ScheduledService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 对外暴露的接口
 */
@RestController
@RequestMapping("/api/v1/schedule")
public class ScheduleClient implements ScheduleFeignClient {

    @Resource
    private TaskService taskService;

    /**
     * 添加任务
     * @param task   任务对象
     * @return       任务id
     */
    @PostMapping("/addTask")
    public void addTask(@RequestBody Task task){
        taskService.addTask(task);
    }

    /**
     * 消费任务
     * @param type 类型
     * @param priority  优先级
     */
    @GetMapping("/pullTask/{type}/{priority}")
    public Task pullTask(@PathVariable int type,@PathVariable int priority){
       return taskService.pullTask(type,priority);
    }
}
